package com.hackerrank.challenges.coinonthetable;

import java.util.Scanner;

public class Solution {
	private static final char TARGET = '*';
	private static class Pos {
		int r, c, k;
		public Pos(int r, int c, int k) {
			this.r = r;
			this.c = c;
			this.k = k;
		}
		public String toString() {
			return r + ", " + c + ", " + k;
		}
	}
	private static int minOperations(char[][] g, Pos pos, int min[][][]) {
		if(pos.r < 0 || pos.r >= g.length || pos.c < 0 || pos.c >= g[pos.r].length || pos.k < 0)
			return Integer.MAX_VALUE - 1;
		if(min[pos.k][pos.r][pos.c] >= 0)
			return min[pos.k][pos.r][pos.c];
		if(g[pos.r][pos.c] == TARGET)
			min[pos.k][pos.r][pos.c] = 0;
		else {
			int minr = minOperations(g, new Pos(pos.r, pos.c + 1, pos.k - 1), min) + (g[pos.r][pos.c] == 'R' ? 0 : 1);
			int mind = minOperations(g, new Pos(pos.r + 1, pos.c, pos.k - 1), min) + (g[pos.r][pos.c] == 'D' ? 0 : 1);
			int minl = minOperations(g, new Pos(pos.r, pos.c - 1, pos.k - 1), min) + (g[pos.r][pos.c] == 'L' ? 0 : 1);
			int minu = minOperations(g, new Pos(pos.r - 1, pos.c, pos.k - 1), min) + (g[pos.r][pos.c] == 'U' ? 0 : 1);
			min[pos.k][pos.r][pos.c] = Math.min(Math.min(minr, mind), Math.min(minl, minu));
		}
		return min[pos.k][pos.r][pos.c];
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), m = in.nextInt(), k = in.nextInt(), min[][][] = new int[k + 1][][];
		char g[][] = new char[n][m];
		in.nextLine();
		for(int i = 0; i < n; i++)
			g[i] = in.nextLine().toCharArray();
		for(int i = 0; i <= k; i++) {
			min[i] = new int[g.length][];
			for(int r = 0; r < g.length; r++) {
				min[i][r] = new int[g[r].length];
				for(int c = 0; c < g[r].length; c++)
					min[i][r][c] = -1;
			}
		}
		int minOp = minOperations(g, new Pos(0, 0, k), min);
		if(minOp >= Integer.MAX_VALUE - 1)
			System.out.println(-1);
		else
			System.out.println(minOp);
	}
}
